#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

constexpr unsigned long empty=-1;
constexpr bool debugMode=true;

template<typename elem>
void showAll(const std::vector<elem> &raw){
    for(int i=0;i<=int(raw.size())-1;++i){
        std::cout<<raw[i]<<' ';
    }std::cout<<std::endl;
}

class cowQuery{
public:
    std::vector<unsigned long> stage1;
    std::vector<unsigned long> stage2;
    std::vector<unsigned long> stage3;
    cowQuery():stage1(60,empty),stage2(60,empty),stage3(60,empty){
        stage1[0]=0;
        stage2[0]=0;
        stage3[0]=1;
    };
    ~cowQuery()=default;

    unsigned long query(const int nth){
        return queryRecursive(nth);
    }

private:
    unsigned long queryRecursive(const int nth){
        const int i{nth-1};
        if(stage1[i]!=empty){
            return stage1[i]+stage2[i]+stage3[i];
        }

        queryRecursive(nth-1);
        stage1[i]=stage3[i-1];
        stage2[i]=stage1[i-1];
        stage3[i]=stage2[i-1]+stage3[i-1];
        return stage1[i]+stage2[i]+stage3[i];
    }
};



int main(){
    cowQuery test{};
    
    int n;
    scanf("%d",&n);
    while (n!=0){
        std::cout<<test.query(n)<<std::endl;
        scanf("%d",&n);
    }
    


    return 0;
}